package com.ihr360.commons.lang;

import java.security.MessageDigest;
import java.util.UUID;

public final class UUIDGenerator {
    private final static char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    public static String uuid() {
        try {
            MessageDigest salt = MessageDigest.getInstance("SHA-256");
            salt.update(UUID.randomUUID().toString().getBytes("UTF-8"));
            String digest = bytesToHex(salt.digest());
            return digest;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return UUID.randomUUID().toString();
    }

    public static String bytesToHex(byte[] aInput) {
        StringBuffer result = new StringBuffer();
        for (int idx = 0; idx < aInput.length; ++idx) {
            byte b = aInput[idx];
            result.append(digits[(b & 0xf0) >> 4]);
            result.append(digits[b & 0x0f]);
        }
        return result.toString();
    }
    public static String randomUUID(){
        String uuid=UUID.randomUUID().toString();
        return uuid.replaceAll("-","");
    }

}